<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-form-item label="选择楼栋" prop="dId" >
          <el-cascader
            v-model="testvalue"
            :options="downtownList"
            :props="cateProps"
            placeholder="请选择楼栋"
            @change="handleChange"
          ></el-cascader>
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getShopsById(this.queryParams.id)">搜索</el-button>
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>


    <div class="cardbody" style="margin-top: 20px ; margin-bottom: 20px">
      <div class="cardhead" style="display: flex;align-items: center">
        <div class="point" style="height: 10px; width: 10px; border-radius: 5px; background-color:#909399; "></div><span style="margin-left: 5px">空置</span>
        <div class="point" style="height: 10px; width: 10px; border-radius: 5px; background-color:#1890FF; "></div><span style="margin-left: 5px">已出租</span>
        <div class="point" style="height: 10px; width: 10px; border-radius: 5px; background-color:#20B2AA; "></div><span style="margin-left: 5px">已出售</span>
        <div class="point" style="height: 10px; width: 10px; border-radius: 5px; background-color:#E6A23C; "></div><span style="margin-left: 5px">即将到期</span>
        <div class="point" style="height: 10px; width: 10px; border-radius: 5px; background-color:#F56C6C; "></div><span style="margin-left: 5px">租约逾期</span>
      </div>
    </div>
    <div v-for="(item,index) in this.shopsfloor"  class="shopcard">
      <div class="floorinfo" style="width: 100px;text-align: center" >
        <div class="leftfloor">{{item}}层</div>
      </div>
      <div class="shopInfo" style="width: 90%;" >
        <el-card :body-style="{padding: 0}" class="box-card" shadow="hover" style="width: 250px;height: 100px" v-for="(item,indexs) in shopsLength[index]" @click.native="openDialog(shopsInfoList[index][indexs].id)">
          <div  class="headone" v-if="shopsInfoList[index][indexs].state == 0">
            <div style="line-height: 40px;margin-left: 10px">编号：{{ shopsInfoList[index][indexs].code }}({{ shopsInfoList[index][indexs].floorArea }}㎡)</div>
          </div>
          <div  class="shopdowninfo" v-if="shopsInfoList[index][indexs].state == 0">
            <div class="carddown">门牌号：{{ shopsInfoList[index][indexs].room }}</div>
            <div class="carddown">介绍：{{ shopsInfoList[index][indexs].remark }}</div>
          </div>

          <div  class="headtwo" v-if="shopsInfoList[index][indexs].state == 1">
            <div style="line-height: 40px;margin-left: 10px">编号：{{ shopsInfoList[index][indexs].code }}({{ shopsInfoList[index][indexs].floorArea }}㎡)</div>
          </div>
          <div  class="shopdowninfo" v-if="shopsInfoList[index][indexs].state == 1">
            <div class="carddown">门牌号：{{ shopsInfoList[index][indexs].room }}</div>
            <div class="carddown">介绍：{{ shopsInfoList[index][indexs].remark }}</div>
          </div>

          <div  class="headthree" v-if="shopsInfoList[index][indexs].state == 2">
            <div style="line-height: 40px;margin-left: 10px">编号：{{ shopsInfoList[index][indexs].code }}({{ shopsInfoList[index][indexs].floorArea }}㎡)</div>
          </div>
          <div  class="shopdowninfo" v-if="shopsInfoList[index][indexs].state == 2">
            <div class="carddown">门牌号：{{ shopsInfoList[index][indexs].room }}</div>
            <div class="carddown">介绍：{{ shopsInfoList[index][indexs].remark }}</div>
          </div>

          <div  class="headfore" v-if="shopsInfoList[index][indexs].state == 3">
            <div style="line-height: 40px;margin-left: 10px">编号：{{ shopsInfoList[index][indexs].code }}({{ shopsInfoList[index][indexs].floorArea }}㎡)</div>
          </div>
          <div  class="shopdowninfo" v-if="shopsInfoList[index][indexs].state == 3">
            <div class="carddown">门牌号：{{ shopsInfoList[index][indexs].room }}</div>
            <div class="carddown">介绍：{{ shopsInfoList[index][indexs].remark }}</div>
          </div>

          <div  class="headfive" v-if="shopsInfoList[index][indexs].state == 4">
            <div style="line-height: 40px;margin-left: 10px">编号：{{ shopsInfoList[index][indexs].code }}({{ shopsInfoList[index][indexs].floorArea }}㎡)</div>
          </div>
          <div  class="shopdowninfo" v-if="shopsInfoList[index][indexs].state == 4">
            <div class="carddown">门牌号：{{ shopsInfoList[index][indexs].room }}</div>
            <div class="carddown">介绍：{{ shopsInfoList[index][indexs].remark }}</div>
          </div>
        </el-card>
      </div>
    </div>


<!--    点击查看Shop详细信息对话框-->
    <el-dialog
      title="门店信息"
      :visible.sync="dialogVisible"
      width="30%"
      >
      <P>门牌号：{{this.shopInfo.room}}</P>
      <P>编号：{{this.shopInfo.code}}</P>
      <P>占地面积：{{this.shopInfo.floorArea}}&nbsp;&nbsp;㎡</P>
      <P>使用面积：{{this.shopInfo.useArea}}&nbsp;&nbsp;㎡</P>
      <P>所属楼栋：{{this.shopInfo.bName}}</P>
      <P>所属商业区：{{this.shopInfo.dName}}</P>
      <P v-if="this.shopInfo.hireInfo == null">租户信息：<span style="color: #00afff">暂无租户</span></P>
      <P v-else>租户信息：<span style="color: #E6A23C">{{this.shopInfo.hireInfo}}</span></P>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>

  </div>
</template>

<script>
import { listTongji, getTongji, delTongji, addTongji, updateTongji,listbuils, listShopsById } from "@/api/system/tongji";
import {getShops} from "@/api/system/shops";

export default {
  name: "Tongji",
  data() {
    return {
      // 遮罩层
      loading: true,
      dialogVisible: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 租赁统计信息管理表格数据
      tongjiList: [],
      // 存放级联菜单信息
      downtownList:[],
      cateProps:{
        label:'name',
        value:'id',
        children:'zhwyBuildingList',
      },
      // 获取级联菜单点击事件
      testvalue:[],
      shopsfloor:{},
      shopsInfo:[],
      shopInfo:'',
      shopsInfoList:[],
      shopsLength:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        id:'',
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getbuileList();
    // this.getShopsById(1001);

  },
  methods: {

    // 打开详细店铺信息对话框
    openDialog(id){
      this.dialogVisible = true;
      this.shopInfo = '';
      getShops(id).then(response => {
        this.shopInfo = response.data;
        console.log(this.shopInfo);
      });
    },
    // 关闭对话框
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
   // 根据楼栋id获取所有商铺信息
    getShopsById(id){
      this.shopsLength = [];
      this.loading = true;
      // console.log(id)
      listShopsById(id).then(response => {
        this.shopsfloor = response.data.ceng;
        this.shopsInfoList = response.data.sp;
        //通过循环商铺，将每个楼层对应的商铺个数，存储shopsLength数组。
        for (let i=0; i<this.shopsInfoList.length; i++){
          this.shopsLength.push(this.shopsInfoList[i].length);//将每个楼层中的商铺个数放入数组。
        }
        this.loading = false;
      });
    },

    handleChange(testvalue) {
      this.queryParams.id = testvalue[1];
      this.getShopsById(testvalue[1]);
      console.log(testvalue[1]);
    },
    /** 查询楼栋信息管理列表 */
    getbuileList(){
      this.loading = true;
      listbuils(this.queryParams).then(response => {
        this.downtownList = response.rows;
        // this.total = response.total;
        this.getShopsById(this.downtownList[0].zhwyBuildingList[0].id);
        this.testvalue[0] = this.downtownList[0].id;
        this.testvalue[1] = this.downtownList[0].zhwyBuildingList[0].id;

        this.loading = false;
      });
    },
    /** 查询租赁统计信息管理列表 */
    getList() {
      this.loading = true;
      listTongji(this.queryParams).then(response => {
        this.tongjiList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    // resetQuery() {
    //   this.resetForm("queryForm");
    //   this.handleQuery();
    // },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加租赁统计信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTongji(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改租赁统计信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTongji(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTongji(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除租赁统计信息管理编号为"' + ids + '"的数据项？').then(function() {
        return delTongji(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tongji/export', {
        ...this.queryParams
      }, `tongji_${new Date().getTime()}.xlsx`)
    }
  }
};

</script>
<style scoped>
.cardhead .point{
  margin-left: 10px;
}
.shopcard{
  display: flex;
  margin-bottom: 10px;

}

.shopcard .leftfloor{
  width: 50px;
  height: 50px;
  border: solid 1px #ccc;
  margin: 10px auto;
  line-height: 50px;
  box-shadow: #ccc 5px 5px ;
}
.shopcard .shopInfo{
  display: flex;
  /*justify-content: space-around;*/
  flex-wrap: wrap;
}

.shopcard .headone{
  width: 250px;
  height: 40px;
  background-color: #909399;
  margin-bottom: 5px;
}
.shopcard .headtwo{
  width: 250px;
  height: 40px;
  background-color: #1890ff;
  margin-bottom: 5px;
}
.shopcard .headthree{
  width: 250px;
  height: 40px;
  background-color: #20B2AA;
  margin-bottom: 5px;
}
.shopcard .headfore{
  width: 250px;
  height: 40px;
  background-color: #E6A23C;
  margin-bottom: 5px;
}
.shopcard .headfive{
  width: 250px;
  height: 40px;
  background-color: #f56c6c;
  margin-bottom: 5px;
}
.shopcard .carddown{
  margin-left: 10px;
}

.shopcard .box-card{
  /*margin-bottom: 5px;*/
  --n: 4;
  --gap: calc((100% - 250px * var(--n)) / var(--n) / 2);
  margin: 10px var(--gap);
  border-radius: 5px;
}

</style>
